package com.example.kotlintest

import com.example.utils.line
import com.example.utils.lineAround
import java.util.*

fun main() {
    lineAround("arrayIterator()") { arrayIterator() }
    lineAround("OneDArray(6)"){ OneDArray(6) }
    lineAround("twoDArray"){ twoDArray()}

//    arrayIterator()
}
fun arrayIterator(){
    val array8 = arrayOf(intArrayOf(10, 20, 30), longArrayOf(100, 1000, 10000))
    for (item in array8) {
        when (item) {
            is IntArray -> println(Arrays.toString(item))
            is LongArray -> println(Arrays.toString(item))
        }

    }
}

fun OneDArray(size: Int){
//    var array= arrayOf<Int>(1,2,3,4)
    var array=  Array(size,{it.inc()})
    array.forEach {
        print(" it:$it ")
    }
}

/**
 *kotlin二维数组遍历和初始化
 */
fun twoDArray(){

    var array= Array(3){IntArray(3)}
    var data= Array(9,{it.inc()})
    println("data = ${Arrays.toString(data)}")

    var count=0;
//    idx，可以立即为index索引的缩写
    for ((idx1, x) in array.withIndex()) {
        for ((idx2, y) in x.withIndex()) {
            print("array[${idx1}][${idx2}] =${data[count]}")
            array[idx1][idx2] = data[count]
            count++
        }
        println()
    }


    for (one in array) {
        for (two in one) {
            print(" it:$two ")
        }
        println()
    }
//    print("")//故意不换行 捣乱测试
}